package logger2.filter.events;

import java.util.EventObject;

import zerdlib.events.MergableEventObject;

import logger2.Logger;
import logger2.filter.ConfigurableFilter;

public class ConfigurableFilterChangeEvent extends FilterChangeEvent implements MergableEventObject {
	private static final long serialVersionUID = 8233955184421341867L;
	
	public boolean filterOnLogger = false;
	public boolean regexLogger = false;
	public boolean acceptChilds = false;
	
	public boolean filterOnLevel = false;
	public boolean level = false;
	public boolean acceptHigher = false;
	
	public boolean filterOnMessage = false;
	public boolean regexMessage = false;
	
	public boolean filterOnThread = false;
	public boolean regexThread = false;
	
	public boolean filterOnClass = false;
	public boolean regexClass = false;
	
	public boolean filterOnTime = false;
	public boolean hasLowLimit = false;
	public boolean lowLimit = false;
	public boolean hasHighLimit = false;
	public boolean highLimit = false;
	
	public ConfigurableFilterChangeEvent(ConfigurableFilter source) {
		super(source);
	}

	@Override
	public boolean merge(EventObject ev_) {
		if(ev_ instanceof ConfigurableFilterChangeEvent) {
			ConfigurableFilterChangeEvent ev = (ConfigurableFilterChangeEvent) ev_;
			filterOnLogger |= ev.filterOnLogger;
			regexLogger |= ev.regexLogger;
			acceptChilds |= ev.acceptChilds;
			filterOnLevel |= ev.filterOnLevel;
			level |= ev.level;
			acceptHigher |= ev.acceptHigher;
			filterOnMessage |= ev.filterOnMessage;
			regexMessage |= ev.regexMessage;
			filterOnThread |= ev.filterOnThread;
			regexThread |= ev.regexThread;
			filterOnClass |= ev.filterOnClass;
			regexClass |= ev.regexClass;
			filterOnTime |= ev.filterOnTime;
			hasLowLimit |= ev.hasLowLimit;
			lowLimit |= ev.lowLimit;
			hasHighLimit |= ev.hasHighLimit;
			highLimit |= ev.highLimit;
			return true;
		} else {
			Logger.assertion(false, "Tentative de merge d'un ConfigurableFilterChangeEvent avec autre chose");
			return false;
		}			
	}
	
	public boolean containsChange() {
		return filterOnLogger ||
		regexLogger ||
		acceptChilds ||
		filterOnLevel ||
		level ||
		acceptHigher ||
		filterOnMessage ||
		regexMessage ||
		filterOnThread ||
		regexThread ||
		filterOnClass ||
		regexClass ||
		filterOnTime ||
		hasLowLimit ||
		lowLimit ||
		hasHighLimit ||
		highLimit;
	}

}
